package com {
import com.core.Controller;
import com.interfaces.IAction;
import com.interfaces.IController;

import laya.utils.Handler;

public class Factory implements IAction {

	private static var _instance:Factory;
	public static function get inst():Factory {
		return _instance;
	}
	private var controller:IController;

	public function Factory() {
		initController();
	}

	/**
	 * 初始化框架
	 */
	public static function init():void {
		_instance = new Factory();
	}

	public static function initClass(...arge):void {
		for (var i:int = 0; i < arge.length; i++) {
			var object:* = arge[i];
				new object();
		}
	}

	protected function initController():void {
		controller = new Controller();
	}

	public function regActionHandler(action:String, handler:Handler, group:String=null):void {
		controller.regActionHandler(action, handler, group);
	}

	public function regAction(action:String, caller:*, method:Function, group:String=null):void {
		controller.regAction(action, caller, method, group);
	}

	public function removeAllAction(...arge):void {
		controller.removeAllAction.apply(controller, arge);
	}

	public function removeGroup(group:String):void {
		controller.removeGroup(group);
	}

	public function removeGroupActions(group:String, ...arge):void {
		arge.unshift(group);
		controller.removeGroupActions.apply(controller, arge);
	}

	public function removeHandler(action:String, method:Function, group:String = null):void {
		controller.removeHandler(action, method, group);
	}

	public function sendAction(action:String, ...arge):void {
		arge.unshift(action);
		controller.sendAction.apply(controller, arge);
	}

	public function sendGroupAction(group:String, action:String, ...arge):void {
		arge.unshift(action);
		arge.unshift(group);
		controller.sendGroupAction.apply(controller, arge);
	}

}
}
